home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
lang
/
fpc09905c.lha
/
fpc
/
inc
/
system.inc
< prev
next >
Wrap
Text File
|
1998-09-21
|
16KB
|
621 lines
{
$Id: system.inc,v 1.28 1998/08/17 12:24:16 carl Exp $
This file is part of the Free Pascal Run time library.
Copyright (c) 1993,97 by the Free Pascal development team
See the file COPYING.FPC, included in this distribution,
For details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{****************************************************************************
Local types
****************************************************************************}
{
TextRec and FileRec are put in a separate file to make it available to other
units without putting it explicitly in systemh.
This way we keep TP compatibility, and the TextRec definition is available
for everyone who needs it.
}
{$i filerec.inc}
{$i textrec.inc}
Procedure HandleError (Errno : Longint); forward;
type
FileFunc = Procedure(var t : TextRec);
const
{ Random / Randomize constants }
OldRandSeed : Longint = 0;
InitialSeed : Boolean = TRUE;
Seed1 : Longint = 0;
Seed2 : Longint = 0;
Seed3 : Longint = 0;
{ For Error Handling.}
DoError : Boolean = FALSE;
ErrorBase : Longint = 0;
{****************************************************************************
Include processor specific routines
****************************************************************************}
{$IFDEF I386}
{$IFDEF M68K}
{$Error Can't determine processor type !}
{$ENDIF}
{$I i386.inc} { Case dependent, don't change }
{$ELSE}
{$IFDEF M68K}
{$I m68k.inc} { Case dependent, don't change }
{$ELSE}
{$Error Can't determine processor type !}
{$ENDIF}
{$ENDIF}
{****************************************************************************
Routines which have compiler magic
****************************************************************************}
{$I innr.inc}
Function lo(i : Integer) : byte; [INTERNPROC: In_lo_Word];
Function lo(w : Word) : byte; [INTERNPROC: In_lo_Word];
Function lo(l : Longint) : Word; [INTERNPROC: In_lo_long];
Function hi(i : Integer) : byte; [INTERNPROC: In_hi_Word];
Function hi(w : Word) : byte; [INTERNPROC: In_hi_Word];
Function hi(l : Longint) : Word; [INTERNPROC: In_hi_long];
{$ifdef VER0_99_5}
Procedure Inc(var i : Cardinal); [INTERNPROC: In_Inc_DWord];
Procedure Inc(var i : Longint); [INTERNPROC: In_Inc_DWord];
Procedure Inc(var i : Integer); [INTERNPROC: In_Inc_Word];
Procedure Inc(var i : Word); [INTERNPROC: In_Inc_Word];
Procedure Inc(var i : shortint); [INTERNPROC: In_Inc_byte];
Procedure Inc(var i : byte); [INTERNPROC: In_Inc_byte];
Procedure Inc(var c : Char); [INTERNPROC: In_Inc_byte];
Procedure Inc(var p : PChar); [INTERNPROC: In_Inc_DWord];
Procedure Dec(var i : Cardinal); [INTERNPROC: In_Dec_DWord];
Procedure Dec(var i : Longint); [INTERNPROC: In_Dec_DWord];
Procedure Dec(var i : Integer); [INTERNPROC: In_Dec_Word];
Procedure Dec(var i : Word); [INTERNPROC: In_Dec_Word];
Procedure Dec(var i : shortint); [INTERNPROC: In_Dec_byte];
Procedure Dec(var i : byte); [INTERNPROC: In_Dec_byte];
Procedure Dec(var c : Char); [INTERNPROC: In_Dec_byte];
Procedure Dec(var p : PChar); [INTERNPROC: In_Dec_DWord];
{$endif VER0_99_5}
Function chr(b : byte) : Char; [INTERNPROC: In_chr_byte];
Function Length(s : string) : byte; [INTERNPROC: In_Length_string];
Procedure Reset(var f : TypedFile); [INTERNPROC: In_Reset_TypedFile];
Procedure Rewrite(var f : TypedFile); [INTERNPROC: In_Rewrite_TypedFile];
{****************************************************************************
Set Handling
****************************************************************************}
{ Include set support which is processor specific}
{$I set.inc}
{****************************************************************************
Subroutines for String handling
****************************************************************************}
{ Needs to be before RTTI handling }
{$i sstrings.inc}
{$ifdef UseAnsiStrings}
Type
PLongint = ^Longint;
PByte = ^Byte;
{$i astrings.pp}
{$else}
{ Provide dummy procedures needed for rtti}
Procedure decr_ansi_ref (P : pointer);[Alias : 'DECR_ANSI_REF'];
begin
end;
Procedure incr_ansi_ref (P : pointer);[Alias : 'INCR_ANSI_REF'];
begin
end;
{$endif}
{****************************************************************************
Run-Time Type Information (RTTI)
****************************************************************************}
{$ifndef VER0_99_5}
{$i rtti.inc}
{$endif VER0_99_5}
{****************************************************************************
Math Routines
****************************************************************************}
{$ifndef RTLLITE}
function Hi(b : byte): byte;
begin
Hi := b shr 4
end;
function Lo(b : byte): byte;
begin
Lo := b and $0f
end;
{$ifdef VER0_99_5}
Procedure Inc(var i : Cardinal;a: Longint);
Begin
I:=I+A;
End;
Procedure Dec(var i : Cardinal;a: Longint);
Begin
I:=I-A;
End;
Procedure Inc(var i : Longint;a : Longint);
Begin
i:=i+a;
End;
Procedure Dec(var i : Longint;a : Longint);
Begin
i:=i-a;
End;
Procedure Dec(var i : Word;a : Longint);
Begin
i:=i-a;
End;
Procedure Inc(var i : Word;a : Longint);
Begin
i:=i+a;
End;
Procedure Dec(var i : Integer;a : Longint);
Begin
i:=i-a;
End;
Procedure Inc(var i : Integer;a : Longint);
Begin
i:=i+a;
End;
Procedure Dec(var i : byte;a : Longint);
Begin
i:=i-a;
End;
Procedure Inc(var i : byte;a : Longint);
Begin
i:=i+a;
End;
Procedure Dec(var i : shortint;a : Longint);
Begin
i:=i-a;
End;
Procedure Inc(var i : shortint;a : Longint);
Begin
i:=i+a;
End;
Procedure Dec(var c : Char;a : Longint);
Begin
byte(c):=byte(c)-a;
End;
Procedure Inc(var c : Char;a : Longint);
Begin
Byte(c):=byte(c)+a;
End;
Procedure Dec(var p : PChar;a : Longint);
Begin
longint(p):=longint(p)-a;
End;
Procedure Inc(var p : PChar;a : Longint);
Begin
longint(p):=longint(p)+a;
End;
{$endif VER0_99_5}
Function swap (X : Word) : Word;
Begin
swap:=(X and $ff) shl 8 + (X shr 8)
End;
Function Swap (X : Integer) : Integer;
Begin
Swap:=Integer(Swap(Word(X)));
End;
Function swap (X : Longint) : Longint;
Begin
Swap:=(X and $ffff) shl 16 + (X shr 16)
End;
Function Swap (X : Cardinal) : Cardinal;
Begin
Swap:=Swap(Longint(X));
End;
{$endif RTLLITE}
{****************************************************************************
Random function routines
This implements a very long cycle random number generator by combining
three independant generators. The technique was described in the March
1987 issue of Byte.
Taken and modified with permission from the PCQ Pascal rtl code.
****************************************************************************}
{$R-}
{$Q-}
Procedure UseSeed(seed : Longint);Forward;
Function Random : Real;
var
ReturnValue : Real;
begin
if (InitialSeed) OR ((RandSeed <> OldRandSeed) AND NOT InitialSeed) then
Begin
OldRandSeed:=RandSeed;
{ This is a pretty complicated affair }
{ Initially we must call UseSeed when RandSeed is initalized }
{ We must also call UseSeed each time RandSeed is reinitialized }
{ DO NOT CHANGE THE ORDER OF DECLARATIONS IN THIS BLOCK }
{ UNLESS YOU WANT RANDON TO CRASH OF COURSE (CEC) }
InitialSeed:=FALSE;
UseSeed(Randseed);
end;
Inc(Seed1);
Seed1 := (Seed1 * 706) mod 500009;
INC(Seed2);
Seed2 := (Seed2 * 774) MOD 600011;
INC(Seed3);
Seed3 := (Seed3 * 871) MOD 765241;
ReturnValue := Seed1/500009.0 +
Seed2/600011.0 +
Seed3/765241.0;
Random := frac(ReturnValue);
end;
Function Random(l : Longint) : Longint;
begin